﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class UIWS : ViewBase
    {
        public UIWS()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwWS = dwMaster;
            if (dwMaster == null)
            {
                IsColorWeave = false;
                KEY = "";
                TXTISIND = "";
                WAUEBM = ""; 
                WALIEFNR = "";
                FBRTU = 0.0;
                FBRTL = 0.0;
                FGRLFD = 0;
                FGRQM = 0;
                MYCOM = "";
                FFDDIK = 0.0;
                FFDDIS = 0.0; 
                 CURRENCY = "";
                PRMEEH = "";
                WSPRICE = "";
                RBRTOL = 0.0;
                EINZNR = "";
                BIND = "";
                RGRLFD = 0.0;
                WAFSTDLG = 0; 
                WASUBSTGR = "".PadRight(3);
                WAHANDICAP = "".PadRight(3);
                WAVORBWA = "".PadRight(3);
                WAVORBFB = "   ";
                WANACHBDR = "".PadRight(3);
                WAVORBAP = "".PadRight(3);
                WAMVB = "";
                DES = "";
                WAGFKZ = " ";
            }
            else
            {
                if (TMV.WAGFKZ == "J")
                    IsColorWeave = true;
                else
                    IsColorWeave = false;
                KEY = "F" + TMV.WAART + TMV.WAVAR;
                TXTISIND = ("00000000 " + TMV.WAART + TMV.WAVAR).PadRight(60);
                DES = TMV.WABEZ;
                WAUEBM = TMV.WAUEBM;
                DENUM = TMV.WAFDDIM; 
                WALIEFNR = TMV.WALIEFNR;
                FBRTU = TMV.WAFBRTU;
                FBRTL = TMV.WAFBRTL;
                FGRLFD = TMV.WAFGRLFD;
                FGRQM = TMV.WAFGRQM;
                FFDDIK = TMV.WAFFDDIK;
                FFDDIS = TMV.WAFFDDIS; 
                RGRLFD = TMV.WARGRLFD; 
                EINZNR = TMV.WAEINZNR;
                RWBRT = TMV.WARWBRT;
                
                BIND = TMV.WABIND;
                MYCOM = (TMV.WALIEFNR).PadRight(8) + (TMV.WAKBON).ToString().Trim().PadRight(4);
                string PR = (TMV.WABIND).ToString().Trim().PadRight(15);
                CURRENCY = PR.Substring(8, 3);
                PRMEEH = PR.Substring(12, 3);
                WSPRICE = PR.Substring(0, 8);
                WAFSTDLG = TMV.WAFSTDLG;
                WASUBSTGR = TMV.WASUBSTGR;
                WAHANDICAP = TMV.WAHANDICAP;
                WAVORBWA = TMV.WAVORBWA;
                WAVORBFB = TMV.WAVORBFB;
                WANACHBDR = TMV.WANACHBDR;
                WAVORBAP = TMV.WAVORBAP;
                WAMVB = TMV.WAMVB;
                WAGFKZ = TMV.WAGFKZ;
                RBRTOL = TMV.WARBRTOL;
                WARPENDS = GWBBRT*0.01 * GWBF * TMV.WARBRTOL * 0.1;
                RBRTOL = TMV.WARBRTOL;
                //转速*14.4/(纬密/2.54）*效率/100  

            }
        }
        public virtual void OnFGRQMChg(double value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WAFGRQM = FGRQM;
            if (TMV.WAFBRTU == 0)
                return;
            if (FGRQM == 0)
                return;
            double result = Helpers.Helper.RoundX(FGRQM * (0.001 * TMV.WAFBRTU), 1);
            if (FGRLFD == result)
                return;
            if (app.company != "UBT")
            {
                FGRLFD = result;
            }
        }
        public virtual void OnFGRLFDChg(double value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WAFGRLFD = FGRLFD;
            if (TMV.WAFBRTU == 0)
                return;
            if (FGRLFD == 0)
                return;
            double result = Helpers.Helper.RoundX(FGRLFD / (0.001 * TMV.WAFBRTU), 1);
            if (FGRQM == result)
                return;
            FGRQM = result;
        }
        public virtual void OnFBRTLChg(double value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            dwMaster["WAFBRTL"] = FBRTL;

        }
        public virtual void OnFBRTUChg(double value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            dwMaster["WAFBRTU"] = FBRTU;
            dwMaster["WAFBRTL"] = FBRTU;
        }

        public virtual void OnRWBRTChg(double value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WARWBRT = value;
            if (TMV.WARBRTOL == 0)
            {
                RBRTOL = (value / 10 + 10) * 10;
            }
        }
        public virtual void OnRBRTOLChg(double value)
        { 
            TMV.WARBRTOL = value;
            WARPENDS = GWBBRT*0.01 * GWBF * TMV.WARBRTOL * 0.1;
            if (TMV.WARBRTOL == 0)
                return;
            RGRQM = Helper.RoundX((WKG + FKG) * 0.01 / (TMV.WARBRTOL * 0.001), 1);
        }
        public virtual void OnEINZNRChg(string value)
        {

            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            dwMaster["WAEINZNR"] = EINZNR;

        }
        public virtual void OnFFDDISChg(double value)
        {

            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            dwMaster["WAFFDDIS"] = FFDDIS;

        }
        public virtual void OnFFDDIKChg(double value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            dwMaster["WAFFDDIK"] = FFDDIK;
        }
        public virtual void OnBINDChg(string value)
        {

            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            dwMaster["WABIND"] = BIND;

        }
        public override void OnSave()
        {
            if (!IsSaved)
                return;
            if (dwMaster == null)
                return;
            switch (app.company)
            {
                case "SJH":
                    TMV.WAFFDDIK = TMV.WARFDDIK;
                    TMV.WAFFDDIS = TMV.WARFDDIS;
                    TMV.WAFBRTU = TMV.WARWBRT;
                    break;
            }
            Update();
            /*
            string currentkey = KEY;
            KEY = "";
            KEY = currentkey;*/
            base.OnSave();
        }
        public override void SaveCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            try
            {
                Update();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            base.SaveCommand(sender, e);
        }

        public override void OnDESChg(string value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WABEZ = value.Trim().PadRight(40);
        }

        public bool IsValid = false;
        public bool Validate()
        {
            IsValid = true;
            switch (app.company)
            {
                case "TST":
                    IsValid = TSTValicate();
                    break;
                case "SJH":
                    if (TMV.WARFDDIS == 0)
                    {
                        IsValid = false;
                        MessageBox.Show("请定义下机纬密");
                    }
                    if (TMV.WARBRTOL == 0)
                    {
                        IsValid = false;
                        MessageBox.Show("请定义机上幅宽");
                    }
                    if (TMV.WARWBRT == 0)
                    {
                        IsValid = false;
                        MessageBox.Show("请定义坯布幅宽");
                    }
                    break;
                default:
                    break;
            }

            return IsValid;
        }
        public bool TSTValicate()
        {

            if (IsExtProd)
            {
                //if (dwWS["WABIND"].ToString().Trim().Length != 0)
                //{
                //MessageBox.Show("必须先定义外发价格");
                //return false;
                //}
                string price = dwWS["WABIND"].ToString().Substring(0, 8).Trim();
                if (price.Length != 0 && (price == "0.00" || price == "0" || price == ""))
                {
                    //MessageBox.Show("必须先定义外发价格");
                    //return false;

                    if (dwWS["WABIND"].ToString().Substring(8, 3).Trim().Length == 0)
                    {
                        MessageBox.Show("请定义价格货币");
                        return false;
                    }
                    if (dwWS["WABIND"].ToString().Substring(12, 3).Trim().Length == 0)
                    {
                        MessageBox.Show("请定义价格单位");
                        return false;
                    }
                }
                if (dwWS["WALIEFNR"].ToString() == "00000000")
                {
                    MessageBox.Show("必须选择一个供应商，并且不能是自己");
                    return false;
                }
            }
            return IsValid;
        }
        public override void Update()
        {
            this.Focus();
            if (dwWS == null)
                return;

            if (!Validate())
            {
                return;
            }

            TMV.UpdateWASTAMM(dwWS, app.company, 0);
            MessageInfo msg = new MessageInfo();
            msg.Sender = this.RUNID;
            msg.MSGTYPE = "WS2VA";
            msg.ACTION = "WS2VA";
            msg.ART = dwWS["WAART"].ToString();
            msg.VAR = dwWS["WAVAR"].ToString();
            msg.P1 = dwWS["WAFGRQM"].ToString();
            msg.P2 = dwWS["WAFBRTU"].ToString();
            VICC_WFEVENTS.SVWF.CheckEvents("UIMESSAGE", null, "", msg); //通知VA 
            CURRENCY = "";
            WSPRICE = "0";
            PRMEEH = "";
        }

        public void Image_MouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (!System.IO.File.Exists(PHOTOLINK))
            {
                return;
            }
            if (!System.IO.File.Exists(@"C:\WINDOWS\system32\mspaint.exe"))
            {

                return;
            }
            string PATH = "\"" + PHOTOLINK + "\"";
            ProcessStartInfo pinf = new ProcessStartInfo(@"C:\WINDOWS\system32\mspaint.exe", PATH);
            Process pro = Process.Start(pinf);
            //pro.Start();

        }

        public void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            IsImageMax = !IsImageMax;
        }

        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (IsManage)
            {
                LOADBYAUF();
            }
            else
            {
                VICC_WFEVENTS.SVWF.FVA06(this.RUNID); ;
            }
            base.ManageCommand(sender, e);
        }

        public override void NewCommand(object sender, RoutedEventArgs e)
        {

            base.NewCommand(sender, e);
        }


        public virtual void OnWSChg(DataRow row)
        {
            if (row == null)
            {
                PHOTOLINK = "/ImagePackage;component/Images/Chart.png";
                return;
            }
            if (((VWASTAMM)MV).WAFFERTKZ != "E")
            {
                IsExtProd = true;
            }
            else
            {
                IsExtProd = false;
            }
            string path = IMAGEPATH + "\\" + row["WAART"].ToString().Trim() + ".jpg";
            if (!System.IO.File.Exists(path))
            {
                PHOTOLINK = "/ImagePackage;component/Images/Chart.png";
                return;
            }
            PHOTOLINK = path;
        }
        public virtual void OnWAKBONChg(string wak)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            if (wak == "") wak = "0";
            TMV.WAKBON = System.Convert.ToDouble(wak);
        }

        public override void LOADBYAUF()
        {
            if (!IsCanLoad)
                return;
            TBMain.Clear();
            base.LOADBYAUF();
            if (ORDERNUM.Length < 23)
            {
                return;
            }
            PM["WART"] = ORDERNUM.Substring(1, 22);
            SResult = TMV.LOADWS(PM);
            MergeData(SResult, true);
            if (!IsAuto)
                return;
            if (TBMain.Rows.Count > 0)
                return;
            DataRow dwDWS = null;
            if (IsUBT)
            {
                dwData = TBMain.NewRow();
                dwData["WAMANDANT"] = app.Mandant;
                dwData["WADART"] = ORDERNUM.Substring(1, 20);
                dwData["WADVAR"] = "  ";
                SResult = TMV.QWSDART(dwData);
                if (SResult.Tables[0].Rows.Count > 0)
                {
                    dwDWS = SResult.Tables[0].Copy().Rows[0];
                }
            }
            if (dwDWS != null)
            {
                PM["dwDWS"] = dwDWS;
            }
            PM["ART"] = ORDERNUM.Substring(1, 20);
            PM["VAR"] = ORDERNUM.Substring(21, 2);
            PM["BEZ"] = DES;
            PM["PROGRP"] = PRODGRP;
            PM["ARTGRP"] = ARTGRP;
            PM["FDDIM"] = DENUM; 
            PM["WABIND"] = "0.00".PadRight(12) + "M  ";
            if (IsExtProd)
            {
                PM["PRODTYP"] = "Z"; 
            }
            else
            {
                PM["PRODTYP"] = "E";
            }
            PM["WAGFKZ"] = "J";
            TMV.NEWWS(PM);
            vwMaster.View.MoveCurrentToFirst();
        }
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            if (TMV.WAVAR == "  ")
                return;
            filter = "WAVAR='" + TMV.WAVAR + "'";
            rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach(DataRow row in rows)
            { 
                TMV.DeleteWASTAMM(row, 1);
                row.Delete();
            }
            vwMaster.View.MoveCurrentToFirst();
            base.DeleteCommand(sender, e);
        }

    }
    public partial class UIWS
    {
        public VWASTAMM TMV
        {
            get
            {
                return (VWASTAMM)MV;
            }
        }
        #region ==IsWS22===========
        public static readonly DependencyProperty IsWS22Property = DependencyProperty.Register("IsWS22",
        typeof(bool), typeof(UIWS),
        new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsWS22Changed));
        public bool IsWS22
        {
            get
            {
                return (bool)GetValue(IsWS22Property);
            }
            set
            {
                SetValue(IsWS22Property, value);
            }
        }
        private static void OnIsWS22Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.IsWS22 = (bool)e.NewValue;
            }
        }
        #endregion 
        #region ==IsWS22R===========
        public static readonly DependencyProperty IsWS22RProperty = DependencyProperty.Register("IsWS22R",
        typeof(bool), typeof(UIWS),
        new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsWS22RChanged));
        public bool IsWS22R
        {
            get
            {
                return (bool)GetValue(IsWS22RProperty);
            }
            set
            {
                SetValue(IsWS22RProperty, value);
            }
        }
        private static void OnIsWS22RChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.IsWS22R = (bool)e.NewValue;
            }
        }
        #endregion
        #region ==IsWS22T===========
        public static readonly DependencyProperty IsWS22TProperty = DependencyProperty.Register("IsWS22T",
        typeof(bool), typeof(UIWS),
        new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsWS22TChanged));
        public bool IsWS22T
        {
            get
            {
                return (bool)GetValue(IsWS22TProperty);
            }
            set
            {
                SetValue(IsWS22TProperty, value);
            }
        }
        private static void OnIsWS22TChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.IsWS22T = (bool)e.NewValue;
            }
        }
        #endregion 
        #region ==IsCO===========
        public static readonly DependencyProperty IsCOProperty = DependencyProperty.Register("IsCO",
        typeof(bool), typeof(UIWS),
        new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCOChanged));
        public bool IsCO
        {
            get
            {
                return (bool)GetValue(IsCOProperty);
            }
            set
            {
                SetValue(IsCOProperty, value);
            }
        }
        private static void OnIsCOChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.IsCO = (bool)e.NewValue;
            }
        }
        #endregion
        #region ==IsWS03===========
        public static readonly DependencyProperty IsWS03Property = DependencyProperty.Register("IsWS03",
        typeof(bool), typeof(UIWS),
        new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsWS03Changed));
        public bool IsWS03
        {
            get
            {
                return (bool)GetValue(IsWS03Property);
            }
            set
            {
                SetValue(IsWS03Property, value);
            }
        }
        private static void OnIsWS03Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.IsWS03 = (bool)e.NewValue;
            }
        }
        #endregion
        #region ==DENUM===========
        public static readonly DependencyProperty DENUMProperty = DependencyProperty.Register("DENUM",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDENUMChanged));
        public string DENUM
        {
            get
            {
                return (string)GetValue(DENUMProperty);
            }
            set
            {
                SetValue(DENUMProperty, value);

            }
        }
        private static void OnDENUMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.DENUM = (string)e.NewValue;
                src.OnDENUMChg((string)e.NewValue);
            }
        }
        public virtual void OnDENUMChg(string value)
        {
            if (TMV == null)
                return;
            TMV.WAFDDIM = value;
        }
        #endregion

        #region ==GFDISM===========
        public static readonly DependencyProperty GFDISMProperty = DependencyProperty.Register("GFDISM",
        typeof(double), typeof(UIWS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnGFDISMChanged));
        public double GFDISM
        {
            get
            {
                return (double)GetValue(GFDISMProperty);
            }
            set
            {
                SetValue(GFDISMProperty, value);
            }
        }
        private static void OnGFDISMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.GFDISM = (double)e.NewValue;
                src.OnGFDISMChg((double)e.NewValue);
            }
        }
        public virtual void OnGFDISMChg(double value)
        {
            
        }
        #endregion       
        
      
        #region ==PHOTOLINK===========
        public static readonly DependencyProperty PHOTOLINKProperty = DependencyProperty.Register("PHOTOLINK",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("/ImagePackage;component/Images/Chart.png", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPHOTOLINKChanged));
        public string PHOTOLINK
        {
            get
            {
                return (string)GetValue(PHOTOLINKProperty);
            }
            set
            {
                SetValue(PHOTOLINKProperty, value);
            }
        }
        private static void OnPHOTOLINKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.PHOTOLINK = (string)e.NewValue;
            }
        }
        #endregion

        #region ==WALIEFNR===========
        public static readonly DependencyProperty WALIEFNRProperty = DependencyProperty.Register("WALIEFNR",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWALIEFNRChanged));
        public string WALIEFNR
        {
            get
            {
                return (string)GetValue(WALIEFNRProperty);
            }
            set
            {
                SetValue(WALIEFNRProperty, value);
                OnLIEFNRChg(value);
                if (MV == null)
                    return;
                if (!IsEdit)
                    return;
                if (dwMaster == null)
                    return;
                if (value == "00000000")
                {
                    MessageBox.Show("请选择其他供应商");
                    return;
                }
                ((VWASTAMM)MV).WALIEFNR = value;
            }
        }
        public virtual void OnLIEFNRChg(string ls)
        { }
        private static void OnWALIEFNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WALIEFNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==LSLIEFNA===========
        public static readonly DependencyProperty LSLIEFNAProperty = DependencyProperty.Register("LSLIEFNA",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLSLIEFNAChanged));
        public string LSLIEFNA
        {
            get
            {
                return (string)GetValue(LSLIEFNAProperty);
            }
            set
            {
                SetValue(LSLIEFNAProperty, value);
            }
        }
        private static void OnLSLIEFNAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.LSLIEFNA = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsExtProd===========
        public static readonly DependencyProperty IsExtProdProperty = DependencyProperty.Register("IsExtProd",
        typeof(bool), typeof(UIWS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsExtProdChanged));
        public bool IsExtProd
        {
            get
            {
                return (bool)GetValue(IsExtProdProperty);
            }
            set
            {
                SetValue(IsExtProdProperty, value);
            }
        }
        private static void OnIsExtProdChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.IsExtProd = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsImage===========
        public static readonly DependencyProperty IsImageProperty = DependencyProperty.Register("IsImage",
        typeof(bool), typeof(UIWS),
        new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsImageChanged));
        public bool IsImage
        {
            get
            {
                return (bool)GetValue(IsImageProperty);
            }
            set
            {
                SetValue(IsImageProperty, value);
            }
        }
        private static void OnIsImageChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.IsImage = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsImageMax===========
        public static readonly DependencyProperty IsImageMaxProperty = DependencyProperty.Register("IsImageMax",
        typeof(bool), typeof(UIWS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsImageMaxChanged));
        public bool IsImageMax
        {
            get
            {
                return (bool)GetValue(IsImageMaxProperty);
            }
            set
            {
                SetValue(IsImageMaxProperty, value);
            }
        }
        private static void OnIsImageMaxChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.IsImageMax = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsColorWeave==========
        public static readonly DependencyProperty IsColorWeaveProperty = DependencyProperty.Register("IsColorWeave",
        typeof(bool), typeof(UIWS),
        new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsColorWeaveIsYDChanged));
        public bool IsColorWeave
        {
            get
            {
                return (bool)GetValue(IsColorWeaveProperty);
            }
            set
            {
                SetValue(IsColorWeaveProperty, value);
            }
        }
        private static void OnIsColorWeaveIsYDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
               src.IsColorWeave = (bool)e.NewValue;
                src.OnIsColorWeaveChg((bool)e.NewValue);
            }
        }
        ///勾选标志位，更新旧色号
        ///新建色号属于新标志
        ///同时WS07的显示要得到更新
        public virtual void OnIsColorWeaveChg(bool value)
        {
            if (dwMaster == null)
                return;
            if (!IsEdit)
                return;
            if(!IsColorWeave)
            {
                TMV.WAGFKZ = " ";
                dwData = TMV.VWF.TBMain.NewRow();
                dwData["WAFMANDANT"] = dwMaster["WAMANDANT"];
                dwData["WAFART"] = dwMaster["WAART"];
                dwData["WAFZUART"] = "F";
                dwData["WAFFILLER"] = " AND WAFZUART='C' ";
                TMV.VWF.UZUART(dwData);
                TMV.UWAGFKZ(dwMaster);
            }
            else
            {
                TMV.WAGFKZ = "J"; 
                dwData = TMV.VWF.TBMain.NewRow();
                dwData["WAFMANDANT"] = dwMaster["WAMANDANT"];
                dwData["WAFART"] = dwMaster["WAART"];
                dwData["WAFZUART"] ="C";
                dwData["WAFFILLER"] = " AND WAFZUART='F' ";
                TMV.VWF.UZUART(dwData);
                TMV.UWAGFKZ(dwMaster);
            }
        }
        #endregion

        #region ==dwWS===========
        public static readonly DependencyProperty dwWSProperty = DependencyProperty.Register("dwWS",
        typeof(DataRow), typeof(UIWS),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWSChanged));
        public DataRow dwWS
        {
            get
            {
                return (DataRow)GetValue(dwWSProperty);
            }
            set
            {
                SetValue(dwWSProperty, value);
                OnWSChg(value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                ((VWASTAMM)MV).dwWS = value;

            }
        }
        private static void OndwWSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.dwWS = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==WART===========
        public static readonly DependencyProperty WARTProperty = DependencyProperty.Register("WART",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWARTChanged));
        public string WART
        {
            get
            {
                return (string)GetValue(WARTProperty);
            }
            set
            {
                SetValue(WARTProperty, value);
                OnWARTChg(value);
            }
        }
        private static void OnWARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WART = (string)e.NewValue;
            }
        }
        public virtual void OnWARTChg(string value)
        {
            ORDERNUM = value;
        }
        #endregion

        #region ==WSPRICE===========
        public static readonly DependencyProperty WSPRICEProperty = DependencyProperty.Register("WSPRICE",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWSPRICEChanged));
        public string WSPRICE
        {
            get
            {
                return (string)GetValue(WSPRICEProperty);
            }
            set
            {
                SetValue(WSPRICEProperty, value);
                if (!IsEdit)
                    return;
                if (dwWS == null)
                    return;
                if (value == null)
                    return;
                if (value.Trim().Length == 0)
                    return;
                if (WSPRICE.Trim() == "0")
                    return;
                if (WSPRICE.Trim() == "0.00")
                    return;
                if (WSPRICE.Trim() == "0.0")
                    return;

                WABIND = Helper.Left(
                Helper.Left(WSPRICE.PadRight(8), 8)
                + Helper.Left(CURRENCY.PadRight(3), 3)
                + "/"
                + PRMEEH.PadRight(15), 15);
            }
        }
        private static void OnWSPRICEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WSPRICE = (string)e.NewValue;
            }
        }
        #endregion
        #region ==WAGFKZ===========
        public static readonly DependencyProperty WAGFKZProperty = DependencyProperty.Register("WAGFKZ",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAGFKZChanged));
        public string WAGFKZ
        {
            get
            {
                return (string)GetValue(WAGFKZProperty);
            }
            set
            {
                SetValue(WAGFKZProperty, value);

            }
        }
        private static void OnWAGFKZChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAGFKZ = (string)e.NewValue;
                src.OnWAGFKZChg((string)e.NewValue);
            }
        }
        public virtual void OnWAGFKZChg(string value)
        {
            if (!IsEdit)
                return;
            TMV.WAGFKZ = value;
        }
        #endregion
        public string WABIND
        {
            get
            {
                return ((VWASTAMM)MV).WABIND;
            }
            set
            {
                if (MV == null) return;
                ((VWASTAMM)MV).WABIND = value;
            }
        }

        #region ==CURRENCY===========
        public static readonly DependencyProperty CURRENCYProperty = DependencyProperty.Register("CURRENCY",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCURRENCYChanged));
        public string CURRENCY
        {
            get
            {
                return (string)GetValue(CURRENCYProperty);
            }
            set
            {
                SetValue(CURRENCYProperty, value);
                if (!IsEdit)
                    return;
                if (dwWS == null)
                    return;
                if (value == null)
                    return;
                if (value.Trim().Length == 0)
                    return;
                WABIND = Helper.Left(
                Helper.Left(WSPRICE.PadRight(8), 8)
                + Helper.Left(CURRENCY.PadRight(3), 3)
                + "/"
                + PRMEEH.PadRight(15), 15);
            }
        }
        private static void OnCURRENCYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.CURRENCY = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PRMEEH===========
        public static readonly DependencyProperty PRMEEHProperty = DependencyProperty.Register("PRMEEH",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPRMEEHChanged));
        public string PRMEEH
        {
            get
            {
                return (string)GetValue(PRMEEHProperty);
            }
            set
            {
                SetValue(PRMEEHProperty, value);
                if (!IsEdit)
                    return;
                if (dwWS == null)
                    return;
                if (value == null)
                    return;
                if (value.Trim().Length == 0)
                    return;
                WABIND = Helper.Left(
                Helper.Left(WSPRICE.PadRight(8), 8)
                + Helper.Left(CURRENCY.PadRight(3), 3)
                + "/"
                + PRMEEH.PadRight(15), 15);
            }
        }
        private static void OnPRMEEHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.PRMEEH = (string)e.NewValue;
            }
        }
        #endregion

        #region ==WAUEBM===========
        public static readonly DependencyProperty WAUEBMProperty = DependencyProperty.Register("WAUEBM",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAUEBMChanged));
        public string WAUEBM
        {
            get
            {
                return (string)GetValue(WAUEBMProperty);
            }
            set
            {
                SetValue(WAUEBMProperty, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                ((VWASTAMM)MV).WAUEBM = value;
            }
        }
        private static void OnWAUEBMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAUEBM = (string)e.NewValue;
            }
        }
        #endregion


        #region ==MYCOM===========
        public static readonly DependencyProperty MYCOMProperty = DependencyProperty.Register("MYCOM",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMYCOMChanged));
        public string MYCOM
        {
            get
            {
                return (string)GetValue(MYCOMProperty);
            }
            set
            {
                SetValue(MYCOMProperty, value);
            }
        }
        private static void OnMYCOMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.MYCOM = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PRODGRP===========
        public static readonly DependencyProperty PRODGRPProperty = DependencyProperty.Register("PRODGRP",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPRODGRPChanged));
        public string PRODGRP
        {
            get
            {
                return (string)GetValue(PRODGRPProperty);
            }
            set
            {
                SetValue(PRODGRPProperty, value);
            }
        }
        private static void OnPRODGRPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.PRODGRP = (string)e.NewValue;

            }
        }
        #endregion

        #region ==ARTGRP===========
        public static readonly DependencyProperty ARTGRPProperty = DependencyProperty.Register("ARTGRP",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnARTGRPChanged));
        public string ARTGRP
        {
            get
            {
                return (string)GetValue(ARTGRPProperty);
            }
            set
            {
                SetValue(ARTGRPProperty, value);
            }
        }
        private static void OnARTGRPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.ARTGRP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==FBRTU===========
        public static readonly DependencyProperty FBRTUProperty = DependencyProperty.Register("FBRTU",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFBRTUChanged));
        public double FBRTU
        {
            get
            {
                return (double)GetValue(FBRTUProperty);
            }
            set
            {
                SetValue(FBRTUProperty, value);
                OnFBRTUChg(value);
            }
        }
        private static void OnFBRTUChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.FBRTU = (double)e.NewValue;
            }
        }
        #endregion


        #region ==RBRTOL===========
        public static readonly DependencyProperty RBRTOLProperty = DependencyProperty.Register("RBRTOL",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRBRTOLChanged));
        public double RBRTOL
        {
            get
            {
                return (double)GetValue(RBRTOLProperty);
            }
            set
            {
                SetValue(RBRTOLProperty, value);

            }
        }
        private static void OnRBRTOLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.RBRTOL = (double)e.NewValue;
                src.OnRBRTOLChg((double)e.NewValue);
            }
        }
        #endregion
        #region ==RWBRT===========
        public static readonly DependencyProperty RWBRTProperty = DependencyProperty.Register("RWBRT",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRWBRTChanged));
        public double RWBRT
        {
            get
            {
                return (double)GetValue(RWBRTProperty);
            }
            set
            {
                SetValue(RWBRTProperty, value);

            }
        }
        private static void OnRWBRTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.RWBRT = (double)e.NewValue;
                src.OnRWBRTChg((double)e.NewValue);
            }
        }
        #endregion
        #region ==FBRTL===========
        public static readonly DependencyProperty FBRTLProperty = DependencyProperty.Register("FBRTL",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFBRTLChanged));
        public double FBRTL
        {
            get
            {
                return (double)GetValue(FBRTLProperty);
            }
            set
            {
                SetValue(FBRTLProperty, value);
                OnFBRTLChg(value);
            }
        }
        private static void OnFBRTLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.FBRTL = (double)e.NewValue;
            }
        }
        #endregion
        #region ==FGRLFD===========
        public static readonly DependencyProperty FGRLFDProperty = DependencyProperty.Register("FGRLFD",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFGRLFDChanged));
        public double FGRLFD
        {
            get
            {
                return (double)GetValue(FGRLFDProperty);
            }
            set
            {
                SetValue(FGRLFDProperty, value);
                OnFGRLFDChg(value);
            }
        }
        private static void OnFGRLFDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.FGRLFD = (double)e.NewValue;
            }
        }
        #endregion
        #region ==FGRQM===========
        public static readonly DependencyProperty FGRQMProperty = DependencyProperty.Register("FGRQM",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFGRQMChanged));
        public double FGRQM
        {
            get
            {
                return (double)GetValue(FGRQMProperty);
            }
            set
            {
                SetValue(FGRQMProperty, value);
                OnFGRQMChg(value);
            }
        }
        private static void OnFGRQMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.FGRQM = (double)e.NewValue;
            }
        }
        #endregion
        #region ==FFDDIK===========
        public static readonly DependencyProperty FFDDIKProperty = DependencyProperty.Register("FFDDIK",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFFDDIKChanged));
        public double FFDDIK
        {
            get
            {
                return (double)GetValue(FFDDIKProperty);
            }
            set
            {
                SetValue(FFDDIKProperty, value);
                OnFFDDIKChg(value);
            }
        }
        private static void OnFFDDIKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.FFDDIK = (double)e.NewValue;
            }
        }

        #endregion
        #region ==FFDDIS===========
        public static readonly DependencyProperty FFDDISProperty = DependencyProperty.Register("FFDDIS",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFFDDISChanged));
        public double FFDDIS
        {
            get
            {
                return (double)GetValue(FFDDISProperty);
            }
            set
            {
                SetValue(FFDDISProperty, value);
                OnFFDDISChg(value);
            }
        }
        private static void OnFFDDISChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.FFDDIS = (double)e.NewValue;
            }
        }
        #endregion
        
        #region ==EINZNR===========
        public static readonly DependencyProperty EINZNRProperty = DependencyProperty.Register("EINZNR",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEINZNRChanged));
        public string EINZNR
        {
            get
            {
                return (string)GetValue(EINZNRProperty);
            }
            set
            {
                SetValue(EINZNRProperty, value);
                OnEINZNRChg(value);
            }
        }
        private static void OnEINZNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.EINZNR = (string)e.NewValue;
            }
        }

        #endregion

        #region ==BIND===========
        public static readonly DependencyProperty BINDProperty = DependencyProperty.Register("BIND",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBINDChanged));
        public string BIND
        {
            get
            {
                return (string)GetValue(BINDProperty);
            }
            set
            {
                SetValue(BINDProperty, value);
                OnBINDChg(value);
            }
        }
        private static void OnBINDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.BIND = (string)e.NewValue;
            }
        }

        #endregion

        #region ==RGRLFD===========
        public static readonly DependencyProperty RGRLFDProperty = DependencyProperty.Register("RGRLFD",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRGRLFDChanged));
        public double RGRLFD
        {
            get
            {
                return (double)GetValue(RGRLFDProperty);
            }
            set
            {
                SetValue(RGRLFDProperty, value);
                OnRGRLFDChg();
            }
        }
        private static void OnRGRLFDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.RGRLFD = (double)e.NewValue;
            }
        }
        public virtual void OnRGRLFDChg()
        { }
        #endregion

        #region ==RGRQM===========
        public static readonly DependencyProperty RGRQMProperty = DependencyProperty.Register("RGRQM",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRGRQMChanged));
        public double RGRQM
        {
            get
            {
                return (double)GetValue(RGRQMProperty);
            }
            set
            {
                SetValue(RGRQMProperty, value);
                
            }
        }
        private static void OnRGRQMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.RGRQM = (double)e.NewValue;
                src.OnRGRQMChg((double)e.NewValue);
            }
        }
        public virtual void OnRGRQMChg(double value)
        {
            if (TMV == null)
                return;
            TMV.WARGRQM = value;
                   
        }
        #endregion
        #region ==WAKBON===========
        public static readonly DependencyProperty WAKBONProperty = DependencyProperty.Register("WAKBON",
        typeof(string), typeof(UIWS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAKBONChanged));
        public string WAKBON
        {
            get
            {
                return (string)GetValue(WAKBONProperty);
            }
            set
            {
                SetValue(WAKBONProperty, value);
                OnWAKBONChg(value);

            }
        }
        private static void OnWAKBONChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAKBON = (string)e.NewValue;
            }
        }
        #endregion

        #region ==WAFSTDLG===========
        public static readonly DependencyProperty WAFSTDLGProperty = DependencyProperty.Register("WAFSTDLG",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAFSTDLGChanged));
        public double WAFSTDLG
        {
            get
            {
                return (double)GetValue(WAFSTDLGProperty);
            }
            set
            {
                SetValue(WAFSTDLGProperty, value);
                OnWAFSTDLGChg();
            }
        }
        private static void OnWAFSTDLGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAFSTDLG = (double)e.NewValue;
            }
        }
        public virtual void OnWAFSTDLGChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WAFSTDLG = WAFSTDLG;
            TMV.WARSTDLG = WAFSTDLG;
        }
        #endregion
        #region ==WAFSTDGW===========
        public static readonly DependencyProperty WAFSTDGWProperty = DependencyProperty.Register("WAFSTDGW",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAFSTDGWChanged));
        public double WAFSTDGW
        {
            get
            {
                return (double)GetValue(WAFSTDGWProperty);
            }
            set
            {
                SetValue(WAFSTDGWProperty, value);
                OnWAFSTDGWChg();
            }
        }
        private static void OnWAFSTDGWChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAFSTDGW = (double)e.NewValue;
            }
        }
        public virtual void OnWAFSTDGWChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WAFSTDGW = WAFSTDGW;
        }
        #endregion

        #region ==WARSTDLG===========
        public static readonly DependencyProperty WARSTDLGProperty = DependencyProperty.Register("WARSTDLG",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWARSTDLGChanged));
        public double WARSTDLG
        {
            get
            {
                return (double)GetValue(WARSTDLGProperty);
            }
            set
            {
                SetValue(WARSTDLGProperty, value);
                OnWARSTDLGChg();
            }
        }
        private static void OnWARSTDLGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WARSTDLG = (double)e.NewValue;
            }
        }
        public virtual void OnWARSTDLGChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WARSTDLG = WARSTDLG;
        }
        #endregion
        #region ==WARSTDGW===========
        public static readonly DependencyProperty WARSTDGWProperty = DependencyProperty.Register("WARSTDGW",
            typeof(double), typeof(UIWS),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWARSTDGWChanged));
        public double WARSTDGW
        {
            get
            {
                return (double)GetValue(WARSTDGWProperty);
            }
            set
            {
                SetValue(WARSTDGWProperty, value);
                OnWARSTDGWChg();
            }
        }
        private static void OnWARSTDGWChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WARSTDGW = (double)e.NewValue;
            }
        }
        public virtual void OnWARSTDGWChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WARSTDGW = WARSTDGW;
        }
        #endregion
        #region ==WARABLOM===========
        public static readonly DependencyProperty WARABLOMProperty = DependencyProperty.Register("WARABLOM",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWARABLOMChanged));
        public string WARABLOM
        {
            get
            {
                return (string)GetValue(WARABLOMProperty);
            }
            set
            {
                SetValue(WARABLOMProperty, value);
                OnWARABLOMChg();
            }
        }
        private static void OnWARABLOMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WARABLOM = (string)e.NewValue;
            }
        }
        public virtual void OnWARABLOMChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WARABLOM = WARABLOM;
        }
        #endregion

        #region ==WASUBSTGR===========
        public static readonly DependencyProperty WASUBSTGRProperty = DependencyProperty.Register("WASUBSTGR",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWASUBSTGRChanged));
        public string WASUBSTGR
        {
            get
            {
                return (string)GetValue(WASUBSTGRProperty);
            }
            set
            {
                SetValue(WASUBSTGRProperty, value);
                OnWASUBSTGRChg();
            }
        }
        private static void OnWASUBSTGRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WASUBSTGR = (string)e.NewValue;
            }
        }
        public virtual void OnWASUBSTGRChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WASUBSTGR = WASUBSTGR;
        }
        #endregion

        #region ==WAHANDICAP===========
        public static readonly DependencyProperty WAHANDICAPProperty = DependencyProperty.Register("WAHANDICAP",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAHANDICAPChanged));
        public string WAHANDICAP
        {
            get
            {
                return (string)GetValue(WAHANDICAPProperty);
            }
            set
            {
                SetValue(WAHANDICAPProperty, value);
                OnWAHANDICAPChg();
            }
        }
        private static void OnWAHANDICAPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAHANDICAP = (string)e.NewValue;
            }
        }
        public virtual void OnWAHANDICAPChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WAHANDICAP = WAHANDICAP;
        }
        #endregion

        #region ==WAVORBWA===========
        public static readonly DependencyProperty WAVORBWAProperty = DependencyProperty.Register("WAVORBWA",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAVORBWAChanged));
        public string WAVORBWA
        {
            get
            {
                return (string)GetValue(WAVORBWAProperty);
            }
            set
            {
                SetValue(WAVORBWAProperty, value);
                OnWAVORBWAChg();
            }
        }
        private static void OnWAVORBWAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAVORBWA = (string)e.NewValue;
            }
        }
        public virtual void OnWAVORBWAChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WAVORBWA = WAVORBWA;
        }
        #endregion
        #region ==WAVORBFB===========
        public static readonly DependencyProperty WAVORBFBProperty = DependencyProperty.Register("WAVORBFB",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAVORBFBChanged));
        public string WAVORBFB
        {
            get
            {
                return (string)GetValue(WAVORBFBProperty);
            }
            set
            {
                SetValue(WAVORBFBProperty, value);
                OnWAVORBFBChg();
            }
        }
        private static void OnWAVORBFBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAVORBFB = (string)e.NewValue;
            }
        }
        public virtual void OnWAVORBFBChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WAVORBFB = WAVORBFB;
        }
        #endregion
        #region ==WANACHBDR===========
        public static readonly DependencyProperty WANACHBDRProperty = DependencyProperty.Register("WANACHBDR",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWANACHBDRChanged));
        public string WANACHBDR
        {
            get
            {
                return (string)GetValue(WANACHBDRProperty);
            }
            set
            {
                SetValue(WANACHBDRProperty, value);

            }
        }
        private static void OnWANACHBDRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WANACHBDR = (string)e.NewValue;
                src.OnWANACHBDRChg((string)e.NewValue);
            }
        }
        public virtual void OnWANACHBDRChg(string value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WANACHBDR = value;
        }
        #endregion
        #region ==WAVORBAP===========
        public static readonly DependencyProperty WAVORBAPProperty = DependencyProperty.Register("WAVORBAP",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAVORBAPChanged));
        public string WAVORBAP
        {
            get
            {
                return (string)GetValue(WAVORBAPProperty);
            }
            set
            {
                SetValue(WAVORBAPProperty, value);
                OnWAVORBAPChg();
            }
        }
        private static void OnWAVORBAPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAVORBAP = (string)e.NewValue;
            }
        }
        public virtual void OnWAVORBAPChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WAVORBAP = WAVORBAP;
        }
        #endregion
        #region ==WAMVB===========
        public static readonly DependencyProperty WAMVBProperty = DependencyProperty.Register("WAMVB",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAMVBChanged));
        public string WAMVB
        {
            get
            {
                return (string)GetValue(WAMVBProperty);
            }
            set
            {
                SetValue(WAMVBProperty, value);
                OnWAMVBChg();
            }
        }
        private static void OnWAMVBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WAMVB = (string)e.NewValue;
            }
        }
        public virtual void OnWAMVBChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WAMVB = WAMVB;
        }
        #endregion

        #region ==PEGPLAN===========
        public static readonly DependencyProperty PEGPLANProperty = DependencyProperty.Register("PEGPLAN",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPEGPLANChanged));
        public string PEGPLAN
        {
            get
            {
                return (string)GetValue(PEGPLANProperty);
            }
            set
            {
                SetValue(PEGPLANProperty, value);
            }
        }
        private static void OnPEGPLANChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.PEGPLAN = (string)e.NewValue;
            }
        }

        #endregion
        #region ==WEAVE===========
        public static readonly DependencyProperty WEAVEProperty = DependencyProperty.Register("WEAVE",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWEAVEChanged));
        public string WEAVE
        {
            get
            {
                return (string)GetValue(WEAVEProperty);
            }
            set
            {
                SetValue(WEAVEProperty, value);
            }
        }
        private static void OnWEAVEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WEAVE = (string)e.NewValue;
            }
        }

        #endregion

        #region ==WTKEY===========
        public static readonly DependencyProperty WTKEYProperty = DependencyProperty.Register("WTKEY",
            typeof(string), typeof(UIWS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWTKEYChanged));
        public string WTKEY
        {
            get
            {
                return (string)GetValue(WTKEYProperty);
            }
            set
            {
                SetValue(WTKEYProperty, value);
            }
        }
        private static void OnWTKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WTKEY = (string)e.NewValue;
            }
        }

        #endregion

        #region ==GWBBRT===========
        public static readonly DependencyProperty GWBBRTProperty = DependencyProperty.Register("GWBBRT",
        typeof(double), typeof(UIWS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnGWBBRTChanged));
        public double GWBBRT
        {
            get
            {
                return (double)GetValue(GWBBRTProperty);
            }
            set
            {
                SetValue(GWBBRTProperty, value);
               
            }
        }
        private static void OnGWBBRTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.GWBBRT = (double)e.NewValue;
                src.OnGWBBRTChg((double)e.NewValue);
            }
        }
        public virtual void OnGWBBRTChg(double value)
        {
            WARPENDS = GWBBRT*0.01 * GWBF * TMV.WARBRTOL * 0.1;
        }
        #endregion


        #region ==GWBF===========
        public static readonly DependencyProperty GWBFProperty = DependencyProperty.Register("GWBF",
        typeof(double), typeof(UIWS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnGWBFChanged));
        public double GWBF
        {
            get
            {
                return (double)GetValue(GWBFProperty);
            }
            set
            {
                SetValue(GWBFProperty, value);
                
            }
        }
        private static void OnGWBFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.GWBF = (double)e.NewValue;
                src.OnGWBFChg((double)e.NewValue);
            }
        }
        public virtual void OnGWBFChg(double value)
        {
            WARPENDS = GWBBRT * 0.01 * GWBF * TMV.WARBRTOL * 0.1;
        }
        #endregion
        #region ==WARPENDS===========
        public static readonly DependencyProperty WARPENDSProperty = DependencyProperty.Register("WARPENDS",
        typeof(double), typeof(UIWS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWARPENDSChanged));
        public double WARPENDS
        {
            get
            {
                return (double)GetValue(WARPENDSProperty);
            }
            set
            {
                SetValue(WARPENDSProperty, value);

            }
        }
        private static void OnWARPENDSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WARPENDS = (double)e.NewValue;
                src.OnWARPENDSChg((double)e.NewValue);
            }
        }
        public virtual void OnWARPENDSChg(double value)
        {
             
        }
        #endregion

        #region ==WKG===========
        public static readonly DependencyProperty WKGProperty = DependencyProperty.Register("WKG",
        typeof(double), typeof(UIWS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWKGChanged));
        public double WKG
        {
            get
            {
                return (double)GetValue(WKGProperty);
            }
            set
            {
                SetValue(WKGProperty, value);

            }
        }
        private static void OnWKGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.WKG = (double)e.NewValue;
                src.OnWKGChg((double)e.NewValue);
            }
        }
        public virtual void OnWKGChg(double value)
        {
            if (TMV.WARBRTOL == 0)
                return;
            RGRQM = Helper.RoundX((WKG + FKG) * 0.01 / (TMV.WARBRTOL * 0.001), 1);
        }
        #endregion
        #region ==FKG===========
        public static readonly DependencyProperty FKGProperty = DependencyProperty.Register("FKG",
        typeof(double), typeof(UIWS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFKGChanged));
        public double FKG
        {
            get
            {
                return (double)GetValue(FKGProperty);
            }
            set
            {
                SetValue(FKGProperty, value);

            }
        }
        private static void OnFKGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWS;
            if (src != null)
            {
                src.FKG = (double)e.NewValue;
                src.OnFKGChg((double)e.NewValue);
            }
        }
        public virtual void OnFKGChg(double value)
        {
            if (TMV.WARBRTOL == 0)
                return;
            RGRQM =Helper.RoundX( (WKG + FKG)*0.01 / (TMV.WARBRTOL * 0.001),1);
        }
        #endregion


    }
}
